package com.example.pt.enums;

public enum Category {
    MOVIE(1, "电影"),
    MUSIC(2, "音乐"),
    STUDY(3, "学习"),
    SOFTWARE(4, "软件"),
    DRAMA(5, "剧集"),
    ANIME(6, "动漫"),
    GAME(7, "游戏"),
    VARIETY(8, "综艺"),
    SPORTS(9, "体育"),
    OTHER(10, "其他");

    private final int value;
    private final String name;

    Category(int value, String name) {
        this.value = value;
        this.name = name;
    }

    public int getValue() {
        return value;
    }

    public String getName() {
        return name;
    }

    /**
     * 根据分类值获取对应的枚举实例（自动处理大于10的情况）
     * @param value 分类值（任意整数）
     * @return 对应的枚举实例，默认返回OTHER
     */
    public static Category fromValue(int value) {
        for (Category category : Category.values()) {
            if (category != OTHER && category.getValue() == value) {
                return category;
            }
        }
        return OTHER;
    }

    public static String getNameByValue(int value) {
        return fromValue(value).getName();
    }

    public static int getValueByName(String name) {
        for (Category category : Category.values()) {
            if (category.getName().equals(name)) {
                return category.getValue();
            }
        }
        return 10;
    }
}